home *** CD-ROM | disk | FTP | other *** search
/ 5 Star Games: DOS Edition 2 / 5 Star Games - DOS Edition (1995)(Ready to Run).iso / dbc / db_curs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-28  |  3.0 KB  |  137 lines

  1. /****************************************************************************/
  2. /*                         DATABOSS MODULE: DB_CURS.C                       */
  3. /****************************************************************************/
  4.  
  5. #include "db_lsc.h"
  6.  
  7. #include <stdlib.h>
  8. #include <dos.h>
  9. #include "db_types.h"
  10. #include "db_curs.h"
  11. #ifdef __TURBOC__
  12.    #include "db_dos.h"
  13.    #include <conio.h>
  14. #else
  15.     #include <graph.h>
  16. #endif
  17. #include "db_conio.h"
  18.  
  19. /****************************  GLOBAL VARIABLES  ****************************/
  20.  
  21. bool      ins_flag;
  22. cursortyp linecurs;
  23. cursortyp inscurs;
  24. cursortyp hidecurs;
  25. cursortyp origcurs;
  26.  
  27. /***************************  INTERNAL VARIABLES  ***************************/
  28.  
  29. static bool initialized = False;
  30.  
  31. /*****************************  IMPLEMENTATION  *****************************/
  32.  
  33. void vidfun(int10_ah fun, modetyp *md)
  34. {
  35.     union REGS regs;
  36.  
  37.     regs.h.ah = (byte) fun;
  38.     switch (fun) {
  39.         case _SetMode :
  40.             regs.h.al = md->mode;
  41.  
  42. /*            swinterrupt(0x10,®s,®s); */
  43.  
  44.          int86(0x10, ®s, ®s);
  45.            break;
  46.         case _GetMode :
  47.  
  48. /*            swinterrupt(0x10,®s,®s); */
  49.  
  50.          int86(0x10, ®s, ®s);
  51.             md->mode = regs.h.al;
  52.             md->cols = regs.h.ah;
  53.             md->dpage = regs.h.bh;
  54.            break;
  55.     }
  56. }
  57.  
  58. void curfun(int10_ah fun, cursortyp *curs)
  59. {
  60.     union REGS regs;
  61.     modetyp m;
  62.  
  63.     vidfun(_GetMode,&m);
  64.     regs.h.bh = m.dpage;
  65.     regs.h.ah = (byte) fun;
  66.     switch (fun) {
  67.         case _SetCTyp :
  68.          regs.h.ch = curs->b_scan;
  69.          regs.h.cl = curs->e_scan;
  70.  
  71. /*       swinterrupt(0x10,®s,®s); */
  72.  
  73.          int86(0x10, ®s, ®s);
  74.          regs.x.ax = regs.x.bx;            /* this line was put into        */
  75.          break;                            /* pascal to hopefully fix a bug */
  76.         case _SetCPos :
  77.          gotoxy(curs->ccol, curs->crow);
  78.          break;
  79.  
  80. /*       
  81.          regs.h.dh = curs->crow - 1;
  82.             regs.h.dl = curs->ccol - 1;
  83.             swinterrupt(0x10,®s,®s);
  84. */
  85.  
  86.         case _GetCurs :
  87.  
  88. /*       swinterrupt(0x10,®s,®s); */
  89.  
  90.          int86(0x10, ®s, ®s);
  91.          curs->b_scan = regs.h.ch;
  92.          curs->e_scan = regs.h.cl;
  93.          curs->crow = regs.h.dh + 1;
  94.          curs->ccol = regs.h.dl + 1;
  95.            break;
  96.     }
  97. }
  98.  
  99. void toggleins(cursortyp *curs)
  100. {
  101.     ins_flag = (bool) (!ins_flag);
  102.     if (ins_flag) {
  103.         curs->b_scan = inscurs.b_scan;
  104.         curs->e_scan = inscurs.e_scan;
  105.         curfun(_SetCTyp,curs);
  106.     }
  107.     else {
  108.         curs->b_scan = linecurs.b_scan;
  109.         curs->e_scan = linecurs.e_scan;
  110.         curfun(_SetCTyp,curs);
  111.     }
  112. }
  113.  
  114. /**********************  UNIT INITIALIZATION/EXIT CODE  *********************/
  115.  
  116. void db_curs_exit(void)
  117. {
  118.     curfun(_SetCTyp,&origcurs);
  119. }
  120.  
  121. void db_curs_init(void)
  122. {
  123.     if (!initialized) {
  124.         initialized = True;
  125.         ins_flag = False;
  126.         curfun(_GetCurs,&origcurs);
  127.         linecurs = origcurs;
  128.         inscurs = origcurs;
  129.         inscurs.b_scan = 0;
  130.         hidecurs = origcurs;
  131.         hidecurs.b_scan = hidecurs.b_scan | 0x30;
  132.         atexit(db_curs_exit);
  133.     }
  134. }
  135.  
  136. /****************************  END OF DB_CURS.C  ****************************/
  137.